<?php
namespace app\api\model;

use think\Model;

class Category extends Base
{
    protected $table = 'category';
    protected $autoWriteTimestamp = 'datetime';

    public function img()
    {
        return $this->belongsTo('Image', 'topic_img_id', 'id');
    }

    public function products()
    {
        return $this->hasMany('Product', 'category_id', 'id');
    }


    public function getCates()
    {

        try{

            $cates = $this->with(['img'])->select();

        }catch (\Exception $e){

            $cates =null;

        }

        return $cates;
    }


    public function getCateProducts()
    {
        try{

            $goods = $this->with(['products','img'])->select();

        }catch (\Exception $e){

            $goods =null;

        }

        return $goods;
    }




}